yjx.directive('nPicker', ['$timeout',function ($timeout) {
    return {
        restrict: '',
        scope: {
            data: '=pickerData',
            valueChange: '=pickerValueChange',
            change: '=pickerChange',
            select: '=pickerSelect',
            id: '@pickerId',
            title: '@pickerTitle',
            selectedIndex: '=pickerIndex',
        },
        link: function ($scope, elem, attr) {
            $scope.$watch('data', function () {
                // console.log($scope.data);
                if ($scope.data && $scope.data.length > 0) {
                    var picker = new Picker({
                        data: $scope.data,
                        selectedIndex: $scope.selectedIndex,
                        title: $scope.title ? $scope.title : ''
                    });
                    picker.on('picker.select', function (selectedVal, selectedIndex) {
                        $scope.select(selectedVal, selectedIndex);
                    })

                    picker.on('picker.valuechange', function (selectedVal, selectedIndex) {
                        if ($scope.valueChange) {
                            $scope.valueChange(selectedVal, selectedIndex);
                        } else {
                            return;
                        }
                    });
                    picker.on('picker.change', function (selectedVal, selectedIndex) {
                        if ($scope.change) {
                            $scope.change(selectedVal, selectedIndex);
                        } else {
                            return;
                        }
                    });
                    elem.bind('click', function () {
                        picker.show()
                    })
                }
            }, true)
           
        }
    }
}])